home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Complete orthogonal decomposition.
-
- // Syntax: C = cod ( A , TOL )
-
- // Description:
-
- // Cod computes a decomposition A = U*T*V, where U and V are
- // unitary, T = [R, 0; 0, 0] has the same dimensions as A, and R
- // is upper triangular and nonsingular of dimension rank(A). Rank
- // decisions are made using TOL, which defaults to approximately
- // MAX(SIZE(A))*NORM(A)*EPS.
-
- // Cod returns a list with elements `u', `r', and `v', such that
- // A = u*r*v
-
- // Reference:
- // G.H. Golub and C.F. Van Loan, Matrix Computations, Second
- // Edition, Johns Hopkins University Press, Baltimore, Maryland,
- // 1989, sec. 5.4.2.
-
- // This file is a translation of cod.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- // Dependencies
- require trap2tri
-
- //-------------------------------------------------------------------//
-
- cod = function ( A , tol )
- {
- global (eps)
-
- m = A.nr; n = A.nc;
-
- // QR decomposition.
- qra = qr(A, "p"); // A*qra.p = qra.u*qra.r (A*P = U*R)
- V = qra.p'; // A = URV
- if (!exist (tol))
- {
- // |R[1;1]| approx NORM(A).
- tol = max(m,n)*eps*abs(qra.r[1;1]);
- }
-
- // Determine r = effective rank.
- r = sum(abs(diag(qra.r)) > tol);
- r = r[1]; // Fix for case where R is vector.
- qra.r = qra.r[1:r;]; // Throw away negligible rows (incl. all zero rows, m>n).
-
- if (r != n)
- {
- // Reduce nxr R' = r [L] to lower triangular form: QR' = [Lbar].
- // n-r [M] [0]
-
- tr = trap2tri(qra.r'); // [Q, R] = trap2tri(qra.r');
- V = tr.q*V;
- qra.r = tr.r';
- }
-
- return << u = qra.q; r = qra.r; v = V >>;
- };
-